//纯粹的源数据转存
let gulp     = require("gulp"); 
let connect  = require("gulp-connect") //运行网络服务器的插件
// let proxy    = require('http-proxy-middleware')
// var sass     = require('gulp-sass');
// sass.compiler = require('node-sass');
//开发环境
let { paths , proxyList } = require("./gulp.config");

function devStyles(){
      return gulp.src(paths.styles.src)
            // .pipe(sass().on('error', sass.logError))
            .pipe(gulp.dest(paths.styles.dist))//源数据转存操作
            .pipe(connect.reload());//重新刷新页面
}
function devScripts(){
      return gulp.src(paths.scripts.src)
      .pipe(gulp.dest(paths.scripts.dist))
      .pipe(connect.reload());
}
function devHtml(){
      return gulp.src(paths.html.src)
      .pipe(gulp.dest(paths.html.dist))
      .pipe(connect.reload());
}

function useconnect(){
      connect.server({
            root : "./dist",
            port : 8888, 
            livereload : true,
            // middleware : function(connect, opt) {
            //       let arr = [];
            //       for(let attr in proxyList){
            //             arr.push( proxy ( attr , proxyList[attr]))
            //       }
            //       return arr;
            // }
      });
}

//监听
function watch(){
      gulp.watch(paths.styles.src,devStyles)
      gulp.watch(paths.scripts.src,devScripts)
      gulp.watch(paths.html.src,devHtml)
}

                  //执行队列(异步执行)
let dev = gulp.series( gulp.parallel( useconnect , watch ) );

module.exports  = dev; 
